﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace AxeFrog.Composition
{
	public class ExtensionsConfigurationSection : ConfigurationSection
	{
		[ConfigurationProperty("assemblies", IsDefaultCollection = true)]
		public LoadElementCollection Assemblies
		{
			get { return (LoadElementCollection)base["assemblies"]; }
		}
	}

	public sealed class LoadElement : ConfigurationElement
	{
		[ConfigurationProperty("path", IsRequired = true)]
		public string Path
		{
			get { return (string)this["path"]; }
			set { this["path"] = value; }
		}
	}

	public class LoadElementCollection : ConfigurationElementCollection
	{
		protected override ConfigurationElement CreateNewElement()
		{
			return new LoadElement();
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((LoadElement)element).Path;
		}

		public override ConfigurationElementCollectionType CollectionType
		{
			get { return ConfigurationElementCollectionType.BasicMap; }
		}

		protected override string ElementName
		{
			get { return "load"; }
		}

		public LoadElement this[int index]
		{
			get { return (LoadElement)BaseGet(index); }
			set
			{
				if (BaseGet(index) != null)
					BaseRemoveAt(index);
				BaseAdd(index, value);
			}
		}

		new public LoadElement this[string regex]
		{
			get { return (LoadElement)BaseGet(regex); }
		}
	}
}